<?php

namespace Block\Controllers;

use Illuminate\Http\Request;
use Block\Model\Currencies as Model;

/**
 *  基础货币汇率控制器
 */
class CurrenciesController extends Controller
{
    
    /**
     * 构造函数
     */
    public function __construct()
    {
        
    }

    /**
     * 获取单个基础货币汇率
     *
     * @return void
     */
    public function index(string $base='USD'){


        $model = new Model();
        $data = $model->where('symbol',$base)->firstOrFail(['symbol as base','symbols','timestamp']);
        $data = $data->toArray();
        $data['symbols'] = json_decode($data['symbols']);
        if($data){
            return $this->response($data);
         }else{
             return $this->response([],404,'Not found');
         }
       
    }

     /**
     * 获取所有支持的基础货币
     *
     * @return void
     */
    public function currencies(){
        $data = Model::get(['symbol','is_autoupdate','timestamp']);
        return $this->response($data->toArray());
    }

}
